package net.wanho.controller;


import net.wanho.po.Cart;
import net.wanho.service.CartService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import lombok.RequiredArgsConstructor;



import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 购物车表 前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2025-09-25
 */
@Api(tags = "购物车表接口")
@RestController
@RequestMapping("/cart")
@RequiredArgsConstructor
public class CartController {

    private final CartService cartService;



    @ApiOperation("购物车表分页查询")
    @GetMapping("/list")
    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") int pageNum,
                              @ApiParam("页大小") @RequestParam(defaultValue = "5") int pageSize,
                              @ApiParam("查询条件") Cart cart){
        PageInfo<Cart> pageInfo = cartService.findPage(pageNum,pageSize,cart);
        return AjaxResult.success(pageInfo);
    }

    @ApiOperation("根据主键查询购物车表")
    @GetMapping("/{cartId}")
    public AjaxResult findById(@PathVariable Serializable cartId){
        return AjaxResult.success(cartService.findById(cartId));
    }

    @ApiOperation("新增购物车表")
    @PostMapping
    public AjaxResult add(@RequestBody Cart cart){
        cartService.add(cart);
        return AjaxResult.success();
    }

    @ApiOperation("修改购物车表")
    @PutMapping
    public AjaxResult modify(@RequestBody Cart cart){
        cartService.modify(cart);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除购物车表")
    @DeleteMapping("/{cartId}")
    public AjaxResult removeById(@PathVariable Serializable cartId){
        cartService.removeById(cartId);
        return AjaxResult.success();
    }

}
